from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template.loader import get_template
from s5211163224_W7.app.models import *
from django.template import Context

def show_com(request):
    if 'comid'in request.GET:
        Report.objects.create(Com_ID = request.GET['comid'],Status = "Well" ,Detail = "-",Date = "-",Who = "-")
        data = Report.objects.all()
        return render_to_response('show_all.html',locals())
    
def add(request):
    return render_to_response('Add_com.html')

def report_com(request):
    return render_to_response('Report_com.html')

def show_report(request):
    if 'comid'and 'comd' in request.GET:
        Report.objects.filter(Com_ID = request.GET['comid']).update(Status = "Error" , Detail = request.GET['comd'],Date = request.GET['date'])
        HistoryError.objects.create(Com_ID = request.GET['comid'],Detail = request.GET['comd'],Date = request.GET['date'])
        data = Report.objects.all()
        return render_to_response('show_all.html',locals())


def fix(request) :
     return render_to_response('Fix_com.html')

def fixcom(request) :
    if 'comid'and 'comd' and 'date' and 'who' in request.GET:
        Report.objects.filter(Com_ID = request.GET['comid']).update(Status = "Well",Detail = request.GET['comd'],Date = request.GET['date'],Who = request.GET['who'])
        HistoryFix.objects.create(Com_ID = request.GET['comid'],Detail = request.GET['comd'],Date = request.GET['date'],Who = request.GET['who'])
        data = Report.objects.all()
        return render_to_response('show_all.html',locals())

def show(request):
        data = Report.objects.all()
        return render_to_response('show_all.html',locals())

def count(request):
    a = Report.objects.filter(Status = "Well")
    i = 0
    for i in range(len(a)):
        i=i+1
    data1 = i
    i = 0
    a = Report.objects.filter(Status = "Error")
    for i in range(len(a)):
        i =i+ 1
        
    data2 = i
    i = 0;
    return render_to_response('Count.html',locals())


def home(request):
    return render_to_response('Home.html')
